import api from './api';

const profileService = {
    /**
     * 获取当前教师的个人信息
     */
    async getProfile() {
        try {
            const response = await api.get('/api/teacher/profile');
            if (response.data.status === 0) {
                return response.data.data;
            } else {
                throw new Error(response.data.message || '获取个人信息失败');
            }
        } catch (error) {
            throw new Error(error.response?.data?.message || error.message);
        }
    },

    /**
     * 注册或更新人脸数据
     * @param {string} faceDescriptor - 从face-api.js计算出的人脸特征码
     */
    async registerFace(faceDescriptor) {
        try {
            const response = await api.post('/api/teacher/profile/register-face', { faceDescriptor });
            if (response.data.status === 0) {
                return response.data.message;
            } else {
                throw new Error(response.data.message || '人脸信息保存失败');
            }
        } catch (error) {
            throw new Error(error.response?.data?.message || error.message);
        }
    },
};

export default profileService;
